<%--
XPTracker - Alternative Agile Tracking Tool
Copyright (C) 2006-2009  Stephen Starkey

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
--%>
<%@ include file="/taglibs.jsp" %>
<%@ attribute name="id" required="true" type="java.lang.String" %>
<%@ attribute name="display" type="java.lang.String" %>
<%@ attribute name="style" type="java.lang.String" %>
<script type="text/javascript">
  <% Integer previewCount = (Integer) jspContext.findAttribute("previewCount");
     if (previewCount == null) {
       previewCount = 0;
     }
     previewCount++;
     jspContext.setAttribute("previewCount", previewCount, PageContext.REQUEST_SCOPE);
  %>
  function showPreview<%=previewCount%>() {
    $('preview-text${previewCount}').value = $('${id}').value;
    var params = Form.serialize($('previewForm${previewCount}'));
    new Ajax.Updater('result${previewCount}', $('previewForm${previewCount}').action,
      {method: 'post', postBody: params, onSuccess: displayPreview${previewCount}});
  }

  function displayPreview${previewCount}(req) {
    var win${previewCount} = new Window('preview${previewCount}', {className: "mac_os_x", width:640, height:480,
      top: 100, right: 100, zIndex: 6, resizable: true, title: "Preview", showEffectOptions: {duration:0},
      draggable:true, wiredDrag: true});
    win${previewCount}.setDestroyOnClose();
    win${previewCount}.getContent().innerHTML = req.responseText;
    win${previewCount}.show();
  }
</script>
<div id="result${previewCount}" style="display:none">result:</div>
<s:form id="previewForm${previewCount}" beanclass="org.xptracker.web.WikiPreviewActionBean" style="display:inline">
  <input type="hidden" id="preview-text${previewCount}" name="text"/>
  <input type="hidden" id="preview-style${previewCount}" name="style" value="${empty style ? 'markdown' : style}"/>
</s:form>
<a href="javascript:showPreview${previewCount}()">${empty display ? "Preview" : display}</a>